Link to this headingHeap Exploitation
TODO:
https://heap-exploitation.dhavalkapil.com/heap_memory.html
https://azeria-labs.com/heap-overflows-and-the-ios-kernel-heap/
https://github.com/str8outtaheap/heapwn
https://github.com/shellphish/how2heap
Windows 7 Heap Implementation
Heap Overflow Exploitation on Windows 10 Explained
Link to this headingHeap Buffer Overflows
- Are more tricker to gain code execution.
- These are usually exploited by rewriting some other data on the heap.
- This can be another string or another object or class.
Link to this headingHeap Spraying
- Allocate a lot of memory until some allocation is always places at a known address
- Works on a low ASLR entropy of heap base
void
Link to this headingFirst Fit
- The last element to be freed is the first one to be allocated.
- Operates like a stack. Last in First out (LIFO)
Link to this headingUnsorted Example
char *a = ; // 0xe4b0010
char *b = ; // 0xe4b0150
;
a = ; // 0xe4b0010
Link to this headingFastbin Example
char *a = ; // 0xe4b010
char *b = ; // 0xe4b030
char *c = ; // 0xe4b050
char *d = ; // 0xe4b070
;
// head -> a -> tail
;
// head -> b -> a -> tail
;
// head -> c -> b -> a -> tail
;
// head -> d -> c -> b -> a -> tail
a = ; // 0xe4b070
// head -> c -> b -> a -> tail [ 'd' is returned ]
b = ; // 0xe4b050
// head -> b -> a -> tail [ 'c' is returned ]
c = ; // 0xe4b030
// head -> a -> tail [ 'b' is returned ]
d = ; // 0xe4b010
// head -> tail [ 'a' is returned ]
Link to this headingHouse of Force (Arbitrary write)
- By corrupting the Top chunk of the heap you trick the heap in to thinking it has more room then it does.
- Using this you can malloc a huge piece of data to wraparound the address space.
- Doing this with the proper size will put the chunk right before the address that you want to write to
- Then do another malloc and you have a pointer to the address that you want to write to.
Link to this headingExample
Link to this headingDouble Free
Link to this headingFastbin Duplication Example
By using a [Double Free](/Exploitation/Heap/Double Free.md) you can return the same pointer twice. This allows modification of the data to one object that will effect the other.
Example:
a = ; // 0xa04010
b = ; // 0xa04030
c = ; // 0xa04050
;
// head -> a -> tail
; // There is a check to make sure that a freed pointer is not freed immediately again. This is mitigated by freeing a different chunk.
// head -> b -> a -> tail
; // Double Free !!
// head -> a -> b -> a -> tail
d = ; // 0xa04010
// head -> b -> a -> tail [ 'a' is returned ]
e = ; // 0xa04030
// head -> a -> tail [ 'b' is returned ]
f = ; // 0xa04010 - Same as 'd' !
// head -> tail [ 'a' is returned ]
Link to this headingFastBin Duplication Consolidation
By freeing a small fastbin block and then mallocing a huge chunk the fastbin chunk is moved to the unsorted bin.
This allows the same chunk to be freed again.
Link to this headingHouse of Force (Arbitrary write)
- By corrupting the Top chunk of the heap you trick the heap in to thinking it has more room then it does.
- Using this you can malloc a huge piece of data to wraparound the address space.
- Doing this with the proper size will put the chunk right before the address that you want to write to
- Then do another malloc and you have a pointer to the address that you want to write to.
Link to this headingExample
Link to this headingFrontlink Exploit
Link to this headingSingle Byte Overflow
- You can update the Size field of a chunk and use it to gain control of a malloc chunk